<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 *  Partner Model Class  
 *  
 * @package XGO CMS v2.0 
 * @subpackage Partner  
 * @author Manh Nguyen - 08/08/2012 
 * @link http://sunsoft.vn
 */
class Partner_model extends DataMapper {

    var $model = 'partner_model';
    var $table = 'partner';

    // --------------------------------------------------------------------
    // Construct
    // --------------------------------------------------------------------
    public function __construct() {
        parent::__construct();
    }

    // --------------------------------------------------------------------
    // Relationships
    // --------------------------------------------------------------------
    var $has_one = array();
    var $has_many = array();
    // --------------------------------------------------------------------
    // Validation
    // --------------------------------------------------------------------
    var $validation = array();
    // --------------------------------------------------------------------

    /**
     * Default order in query select 
     */
    var $default_order_by = array('id');

    function get_partner_id($id) {
        $this->select('id,name')->where('id', $id)->get(1);
        return $this->name;
    }

    /**
     * string value of object
     * 
     * @access private
     * @param null
     * @return string 
     */
    function __toString() {
        return empty($this->title) ? '---empty---' : $this->title;
    }

    /**
     * get partner list
     * @return list(partner)
     */
    function get_list() {
        $this->select('id,name');
        $result = $this->get();
        $partner_list = array();
        foreach ($result as $item) {
            $partner_list[$item->id] = $item->name;
        }
        return $partner_list;
    }

    /**
     * get list partner
     * @param type $zero
     * @return type
     */
    function partner_list($zero = FALSE) {
        $partner = new Partner_model();
        $partner->select('id, name');

        if ($zero) {
            $partner_list = array('' => '--'.$this->lang->line('all').'--');
        } else {
            $partner_list = array();
        }

        foreach ($partner->get() as $item) {
            $partner_list[$item->id] = $item->name;
        }
        return $partner_list;
    }

    /**
     * Array metadata for generate jquery grid
     * show data
     * 
     * @access public
     * @param null
     * @return array 
     */
    function jqgrid_metadata() {
        return array(
            'names' => array(
                'id',
                $this->localize_label('name'),
                $this->localize_label('code'),
                $this->lang->line('homepage')
            ),
            'model' => array(
                array('name' => 'id', 'hidden' => TRUE, 'key' => TRUE,
                    'editrules' => array('edithidden' => TRUE)
                ),
                array('name' => 'name', 'width' => '100',
                    'searchoptions' => array(
                        'sopt' => array('cn', 'nc', 'eq', 'bw', 'bn', 'ew', 'en')
                    )
                ),
                array('name' => 'code', 'width' => '100',
                    'searchoptions' => array(
                        'sopt' => array('cn', 'nc', 'eq', 'bw', 'bn', 'ew', 'en')
                    )
                ),
                array('name' => 'homepage',
                    'searchoptions' => array(
                        'sopt' => array('cn', 'nc', 'eq', 'bw', 'bn', 'ew', 'en')
                    )
                )
            )
        );
    }

}

/* End of file partner.php */
/* Location: ./application/models/partner.php */